package com.zyzd.commontools.utils;

import android.text.TextUtils;
import android.widget.Toast;

import com.zyzd.commontools.AppContext;
import com.zyzd.commontools.R;

/**
 * Created by lzy on 2018/4/28 0028.
 * description ${吐司工具类}
 */

public class ToastUtil {

    private static Toast instance = Toast.makeText(AppContext.getContext(), "", Toast.LENGTH_SHORT);

    private ToastUtil() {
        throw new RuntimeException(ResourceUtil.getString(R.string.common_you_should_not_create_an_instance_of_toastutil_but_use_its_static_method_directly));
    }

    public static void showToast(String msg) {
        showToast(msg, Toast.LENGTH_SHORT);
    }

    public static void showToast(int msgId) {
        showToast(msgId, Toast.LENGTH_SHORT);
    }

    public static void showToast(String msg, int duration) {
        if (TextUtils.isEmpty(msg))
            return;
        instance.setText(msg);
        instance.show();
    }

    public static void showToast(int msgId, int duration) {
        Toast.makeText(AppContext.getContext(), msgId, duration).show();
    }

}
